home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: zivshosh@netvision.net.il ( Ziv)
- Newsgroups: comp.lang.c
- Subject: Re: How to use assert( )
- Date: Wed, 10 Apr 1996 16:44:48 GMT
- Organization: NetVision LTD.
- Message-ID: <316be48b.3354928@news.netvision.net.il>
- References: <4kc3k7$dur@orion.cybercom.net>
- NNTP-Posting-Host: ts005p16.pop4a.netvision.net.il
- X-Newsreader: Forte Agent .99c/16.141
-
- On Mon, 08 Apr 1996 21:22:15 GMT, nield@cybercom.net (John Nield)
- wrote:
-
- >I am interested in the use of the assert() library function (macro?).
- >Neither the FAQ, nor K&R seems to have anything about it. Could
- >someone help me with a breif explanation of its uses and mabye some
- >example code?
- >
- >I'm just starting my first project big enough to split among many
- >people, and from the vague explanations I've heard, assert is supposed
- >to be a usefull way to cause errors when someone passes your code bad
- >values. How do I do this?
- >
- >thanx,
- >
- >;john nield
- >
- Suppose you read a number x which should be between xmin and xmax
- after the reading you could write (assuming <assert.h> is #included)
- assert( x >= xmin && x <= xmax);
- if x is not in the interval the program will exit issuing a message to
- the screen (in DOS at least)
- OK?
- Ziv
-